//
//  HamatonCarAddViewController.swift
//  hamaton-app
//
//  Created by intyt on 2024/4/7.
//

import UIKit
import SnapKit
import Toast_Swift

class HamatonCarAddViewController: HamatonBaseViewController {

    private let addModel: HamatonCarAddViewModel = HamatonCarAddViewModel()

    lazy var addView: HamatonCarAddView = {
        let topV = HamatonCarAddView(frame: .zero)
        topV.delegate = self
        view.addSubview(topV)
        return topV
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        navigationItem.title = "添加人员信息"
        addView.snp.makeConstraints { make in
            make.top.left.right.bottom.equalToSuperview()
        }
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

extension HamatonCarAddViewController: HamatonCarAddViewDelegate {
    func hamatonCarAddViewClickGender(tag: Int) {
        addModel.gender = tag
    }
    
    func hamatonCarAddViewTextFieldChange(text: String?, type: Int) {
        if type == 1 {
            addModel.name = text ?? ""
        }else {
            addModel.phoneNum = text ?? ""
        }
    }
    
    func hamatonCarAddViewSelectedClick(type: Int) {
        if type == 1 {
            let vc: HamatonManagementListViewController = HamatonManagementListViewController()
            weak var weakSelf = self
            vc.backAction = {  (model: HamatonModel) -> Void in
                weakSelf?.addModel.hamatonModel = model
                weakSelf?.addView.hamatonModel = model
            }
            self.navigationController?.pushViewController(vc, animated: false)
        }
    }
    
    func hamatonCarAddViewSaveClick() {
        if let message = self.addModel.jundgeIsSave() {
            self.view.makeToast(message, duration: 3.0, position: .center)
        } else {
            // 调用接口逻辑处理
        }
    }
    
    
}
